package cn.memorynine.consumer.controller;

import cn.memorynine.common.model.ResponseWrapper;
import cn.memorynine.consumer.model.consumer.login.ImageCodeParam;
import cn.memorynine.consumer.model.consumer.login.LoginParam;
import cn.memorynine.consumer.model.consumer.login.NeedImageCodeParam;
import cn.memorynine.consumer.service.ConsumerLoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

@Slf4j
@RestController
@RequestMapping("/consumerLogin")
public class ConsumerLoginController {

    @Autowired
    private ConsumerLoginService consumerLoginService;

    /**
     * 1. 用户登录是否需要图片验证码
     */
    @RequestMapping("/needImageCode")
    public ResponseWrapper needImageCode(@RequestBody @Validated NeedImageCodeParam param){
        return consumerLoginService.needImageCode(param);
    }

    /**
     * 2. 获取图片验证码
     * @return
     */
    @RequestMapping("/imageCode")
    public ResponseWrapper imageCode(@RequestBody @Validated ImageCodeParam param){
        return consumerLoginService.imageCode(param);
    }

    /**
     * 3. 用户登录
     * @return
     */
    @RequestMapping("/login")
    public ResponseWrapper login(@RequestBody @Validated LoginParam param) throws UnsupportedEncodingException {
        return consumerLoginService.login(param);
    }


}
